cmake_minimum_required(VERSION 3.2)
project(MHCUDA)
find_package(OpenMP REQUIRED)
find_package(CUDA QUIET REQUIRED)
if (NOT DISABLE_PYTHON)
  find_package(PythonLibs 3 REQUIRED)
endif()

if (PROFILE OR CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DPROFILE")
endif()
#set(CMAKE_VERBOSE_MAKEFILE on)
if (NOT DEFINED CUDA_ARCH)
  set(CUDA_ARCH "80")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -march=native -Wall -Werror -DCUDA_ARCH=${CUDA_ARCH} -std=c++17 ${OpenMP_CXX_FLAGS}")
if (DEBUGINFO)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
endif()
set(SOURCE_FILES minhashcuda.cc minhashcuda.h wrappers.h private.h kernel.cu)
if (NOT DISABLE_PYTHON)
  list(APPEND SOURCE_FILES python.cc)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I${NUMPY}")
endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  set(NVCC_FLAGS "-G -g")
endif()
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_${CUDA_ARCH} -Xptxas=-v -D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES")
cuda_add_library(MHCUDA SHARED ${SOURCE_FILES} OPTIONS ${NVCC_FLAGS})
target_link_libraries(MHCUDA ${CUDA_curand_LIBRARY})
if(PYTHONLIBS_FOUND)
  include_directories(${PYTHON_INCLUDE_DIRS} ${NUMPY_INCLUDES})
  target_link_libraries(MHCUDA ${PYTHON_LIBRARIES})
endif()
